package com.bishe.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bishe.pojo.UserBill;
import com.bishe.pojo.query.UserBillQuery;
import com.bishe.pojo.response.LoginInfo;
import com.bishe.pojo.response.Result;
import com.bishe.pojo.response.UserInfo;
import com.bishe.service.UserBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("userBill")
@Api(tags = "用户账单控制器")
public class UserBillController {

    @Resource
    private UserBillService userBillService;

    @ApiOperation("新增或修改")
    @PostMapping("/addOrUpdate")
    public Result<?> addOrUpdate(@RequestBody UserBill userBill) {
        userBillService.addOrUpdate(userBill);
        return Result.ok("操作成功");
    }

    @PostMapping("/toPage")
    @ApiOperation("分页查询")
    public Result<?> queryAll(@RequestBody UserBillQuery query) {
        IPage<UserBill> page = userBillService.toPage(query);
        return Result.ok(page);
    }

    @GetMapping("/queryOne/{id}")
    @ApiOperation("根据id查询")
    public Result<?> queryOne(@PathVariable String id) {
        return Result.ok(userBillService.getById(id));
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("主键删除")
    public Result<?> delete(@PathVariable String id) {
        if (StrUtil.isEmpty(id)){
            return Result.error("id不能为空");
        }
        return Result.ok("操作成功",userBillService.removeById(id));
    }

    @PostMapping("/deleteByIds")
    @ApiOperation("批量删除")
    public Result<?> deleteByIds(@RequestBody List<String> ids){
        if (CollUtil.isEmpty(ids)){
            return Result.error("id不能为空");
        }
        return Result.ok(userBillService.removeBatchByIds(ids));
    }

}
